package com.site.wisdom_construction.controller.iotModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.iotModule.AiMonitoringService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/1/21
 * @Description
 */
@Api(tags = "AI监控图片接口")
@RestController
@RequestMapping("AiMonitoring")
@CrossOrigin
public class AiMonitoringController {
    @Autowired
    private AiMonitoringService aiMonitoringService;

    @ApiOperation(value = "删除AI监控图片", notes = "测试数据:")
    @PostMapping("/deleteAiMonitoring")
    public JsonResult deleteAiMonitoring(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = aiMonitoringService.deleteAiMonitoring(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除商品!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除商品失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询AI监控图片", notes = "测试数据:")
    @PostMapping("/findAiMonitoringByPage")
    public Page findAiMonitoringByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(aiMonitoringService.Total(map));
        page.setItems(aiMonitoringService.findAiMonitoringByPage(map));
        return page;
    }

    @ApiOperation(value = "统计数据(根据抓拍类型)", notes = "测试数据:")
    @PostMapping("/countAiMonitoring")
    public OneDataResult countAiMonitoring(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(aiMonitoringService.countAiMonitoring(map));
        return oneDataResult;
    }

    @ApiOperation(value = "查询全部AI监控图片", notes = "测试数据:")
    @PostMapping("/selectAiMonitoring")
    public OneDataResult selectAiMonitoring(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(aiMonitoringService.selectAiMonitoring(map));
        return oneDataResult;
    }
}
